package game.display;

import game.MainController;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

/** Creates a power-up bar that displays what magic powers
 * the player has and how much magic the player can cast
 * 
 * @author DMEComputer
 *
 */

public class PowerUpDisplay
{
	private Rectangle r;
	private int magicType;

	/** Constructs the power-up bar
	 * 
	 * @param rec the rectangle the power-up is displayed in
	 * @param magicType the type of magic 
	 */
	
	public PowerUpDisplay(Rectangle rec, int magicType)
	{
		this.r = rec;
		this.magicType = magicType;
	}

	/** Updates which magic the player has
	 * 
	 * @param g the graphics
	 * @param c the color of the magic
	 */
	
	public void update(Graphics g, Color c) 
	{
		//Sets the background to gray
		g.setColor(Color.gray);
		g.fillRect(r.x,r.y,r.width,r.height);
		
		//if the player has the magic, draw the color
		if(MainController.gameEngine.player.getPlayerMagic(magicType))g.setColor(c);
		else g.setColor(Color.gray);//Draw a gray square saying that they don't have the magic
		
		long timeLeft = MainController.gameEngine.player.getMagicTime(magicType);
		if(timeLeft == 0) g.fillRect(r.x,r.y,r.width,r.height);
		else
		{
			long maxTime = MainController.gameEngine.player.getMaxMagicTime(magicType);
			double percentChange = (double)timeLeft/(double)maxTime;
			g.fillRect(r.x,r.y+(int)(percentChange*r.height),r.width,r.height - (int)((percentChange)*r.height));
		}
	}
}
